<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Kernel (image processing)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Kernel_(image_processing)"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.math.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Kernel_image_processing rootpage-Kernel_image_processing skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Kernel (image processing)</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">For other uses, see <a href="Kernel_(disambiguation)" class="mw-redirect mw-disambig" title="Kernel (disambiguation)">Kernel (disambiguation)</a>.</div>
<style data-mw-deduplicate="TemplateStyles:r1305433154">
/* start https://en.wikipedia.org/ */
.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style>
<p>In <a href="Image_processing" class="mw-redirect" title="Image processing">image processing</a>, a <b>kernel</b>, <b>convolution matrix</b>, or <b>mask</b> is a small <a href="Matrix_(mathematics)" title="Matrix (mathematics)">matrix</a> used for blurring, sharpening, <a href="Image_embossing" title="Image embossing">embossing</a>, <a href="Edge_detection" title="Edge detection">edge detection</a>, and more. This is accomplished by doing a <a href="Convolution" title="Convolution">convolution</a> between the kernel and an <a href="Bitmap_image" class="mw-redirect" title="Bitmap image">image</a>. Or more simply, when each pixel in the output image is a function of the nearby pixels (including itself) in the input image, the kernel is that function.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Details">Details</h2></div>
<p>The general expression of a convolution is
</p><p><span class="mwe-math-element mwe-math-element-block"><span class="mwe-math-mathml-display mwe-math-mathml-a11y" style="display: none;"><math display="block" xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle g_{x,y}=\omega *f_{x,y}=\sum _{i=-a}^{a}{\sum _{j=-b}^{b}{\omega _{i,j}f_{x-i,y-j}}},}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<msub>
<mi>g</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>x</mi>
<mo>,</mo>
<mi>y</mi>
</mrow>
</msub>
<mo>=</mo>
<mi>ω<!-- ω --></mi>
<mo>∗<!-- ∗ --></mo>
<msub>
<mi>f</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>x</mi>
<mo>,</mo>
<mi>y</mi>
</mrow>
</msub>
<mo>=</mo>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mo>=</mo>
<mo>−<!-- − --></mo>
<mi>a</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>a</mi>
</mrow>
</munderover>
<mrow class="MJX-TeXAtom-ORD">
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
<mo>=</mo>
<mo>−<!-- − --></mo>
<mi>b</mi>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>b</mi>
</mrow>
</munderover>
<mrow class="MJX-TeXAtom-ORD">
<msub>
<mi>ω<!-- ω --></mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mo>,</mo>
<mi>j</mi>
</mrow>
</msub>
<msub>
<mi>f</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>x</mi>
<mo>−<!-- − --></mo>
<mi>i</mi>
<mo>,</mo>
<mi>y</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
</mrow>
</msub>
</mrow>
</mrow>
<mo>,</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle g_{x,y}=\omega *f_{x,y}=\sum _{i=-a}^{a}{\sum _{j=-b}^{b}{\omega _{i,j}f_{x-i,y-j}}},}</annotation>
</semantics>
</math></span></span>
</p><p>where <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle g(x,y)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>g</mi>
<mo stretchy="false">(</mo>
<mi>x</mi>
<mo>,</mo>
<mi>y</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle g(x,y)}</annotation>
</semantics>
</math></span><img src="./bf358a54b0375e22ae5f3ab2c3e1a22c0c87e11c.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:6.444ex; height:2.843ex;" alt="{\displaystyle g(x,y)}" loading="lazy"></span> is the filtered image, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle f(x,y)}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>f</mi>
<mo stretchy="false">(</mo>
<mi>x</mi>
<mo>,</mo>
<mi>y</mi>
<mo stretchy="false">)</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle f(x,y)}</annotation>
</semantics>
</math></span><img src="./29473ed0c4e838ac9dbe074535e507166c0e9101.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:6.607ex; height:2.843ex;" alt="{\displaystyle f(x,y)}" loading="lazy"></span> is the original image, <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \omega }">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>ω<!-- ω --></mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \omega }</annotation>
</semantics>
</math></span><img src="./48eff443f9de7a985bb94ca3bde20813ea737be8.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.338ex; width:1.446ex; height:1.676ex;" alt="{\displaystyle \omega }" loading="lazy"></span> is the filter kernel. Every element of the filter kernel is considered by <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle -a\leq i\leq a}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mo>−<!-- − --></mo>
<mi>a</mi>
<mo>≤<!-- ≤ --></mo>
<mi>i</mi>
<mo>≤<!-- ≤ --></mo>
<mi>a</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle -a\leq i\leq a}</annotation>
</semantics>
</math></span><img src="./d711e9fcd9f112ce363e978e55c14c33b6417ddc.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.505ex; width:11.267ex; height:2.343ex;" alt="{\displaystyle -a\leq i\leq a}" loading="lazy"></span> and <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle -b\leq j\leq b}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mo>−<!-- − --></mo>
<mi>b</mi>
<mo>≤<!-- ≤ --></mo>
<mi>j</mi>
<mo>≤<!-- ≤ --></mo>
<mi>b</mi>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle -b\leq j\leq b}</annotation>
</semantics>
</math></span><img src="./646775a15f667afa23a69606e19fbce0920e528a.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.671ex; width:10.958ex; height:2.509ex;" alt="{\displaystyle -b\leq j\leq b}" loading="lazy"></span>.
</p><p>Depending on the element values, a kernel can cause a wide range of effects:
</p>
<table class="wikitable">
<tbody><tr>
<th>Operation
</th>
<th>Kernel ω
</th>
<th>Image result g(x,y)
</th></tr>
<tr>
<td><b><a href="Identity_operation" class="mw-redirect" title="Identity operation">Identity</a></b>
</td>
<td align="center"><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\begin{bmatrix}\ \ 0&\ \ 0&\ \ 0\\\ \ 0&\ \ 1&\ \ 0\\\ \ 0&\ \ 0&\ \ 0\end{bmatrix}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\begin{bmatrix}\ \ 0&\ \ 0&\ \ 0\\\ \ 0&\ \ 1&\ \ 0\\\ \ 0&\ \ 0&\ \ 0\end{bmatrix}}}</annotation>
</semantics>
</math></span><img src="./1fbc763a0af339e3a3ff20af60a8a993c53086a7.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -4.005ex; width:15.469ex; height:9.176ex;" alt="{\displaystyle {\begin{bmatrix}\ \ 0&\ \ 0&\ \ 0\\\ \ 0&\ \ 1&\ \ 0\\\ \ 0&\ \ 0&\ \ 0\end{bmatrix}}}" loading="lazy"></span>
</td>
<td><span class="mw-default-size" typeof="mw:File"></span>
</td></tr>
<tr>
<td rowspan="2"><b><a href="Ridge_detection" title="Ridge detection">Ridge</a></b> or <b><a href="Edge_detection" title="Edge detection">edge detection</a></b>
</td>
<td align="center"><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\begin{bmatrix}0&-1&0\\-1&\ \ 4&-1\\0&-1&0\end{bmatrix}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>4</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>0</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\begin{bmatrix}0&-1&0\\-1&\ \ 4&-1\\0&-1&0\end{bmatrix}}}</annotation>
</semantics>
</math></span><img src="./f9de5913c98629f30efb20b8868e096f202b626c.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -4.005ex; width:17.409ex; height:9.176ex;" alt="{\displaystyle {\begin{bmatrix}0&-1&0\\-1&\ \ 4&-1\\0&-1&0\end{bmatrix}}}" loading="lazy"></span>
</td>
<td><span class="mw-default-size" typeof="mw:File"></span>
</td></tr>
<tr>
<td align="center"><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\begin{bmatrix}-1&-1&-1\\-1&\ \ 8&-1\\-1&-1&-1\end{bmatrix}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>8</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\begin{bmatrix}-1&-1&-1\\-1&\ \ 8&-1\\-1&-1&-1\end{bmatrix}}}</annotation>
</semantics>
</math></span><img src="./f800ad5f76b6c26c729ff0c1fef44284d7cade7a.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -4.005ex; width:17.409ex; height:9.176ex;" alt="{\displaystyle {\begin{bmatrix}-1&-1&-1\\-1&\ \ 8&-1\\-1&-1&-1\end{bmatrix}}}" loading="lazy"></span>
</td>
<td><span class="mw-default-size" typeof="mw:File"></span>
</td></tr>
<tr>
<td><b>Sharpen</b>
</td>
<td align="center"><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\begin{bmatrix}\ \ 0&-1&\ \ 0\\-1&\ \ 5&-1\\\ \ 0&-1&\ \ 0\end{bmatrix}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>5</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>0</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\begin{bmatrix}\ \ 0&-1&\ \ 0\\-1&\ \ 5&-1\\\ \ 0&-1&\ \ 0\end{bmatrix}}}</annotation>
</semantics>
</math></span><img src="./beb8b9a493e8b9cf5deccd61bd845a59ea2e62cc.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -4.005ex; width:17.409ex; height:9.176ex;" alt="{\displaystyle {\begin{bmatrix}\ \ 0&-1&\ \ 0\\-1&\ \ 5&-1\\\ \ 0&-1&\ \ 0\end{bmatrix}}}" loading="lazy"></span>
</td>
<td><span class="mw-default-size" typeof="mw:File"></span>
</td></tr>
<tr>
<td><b><a href="Box_blur" title="Box blur">Box blur</a></b> <br> <small>(<a href="Normalization_(image_processing)" title="Normalization (image processing)">normalized</a>)</small>
</td>
<td align="center"><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {1}{9}}{\begin{bmatrix}\ \ 1&\ \ 1&\ \ 1\\\ \ 1&\ \ 1&\ \ 1\\\ \ 1&\ \ 1&\ \ 1\end{bmatrix}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mn>1</mn>
<mn>9</mn>
</mfrac>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\frac {1}{9}}{\begin{bmatrix}\ \ 1&\ \ 1&\ \ 1\\\ \ 1&\ \ 1&\ \ 1\\\ \ 1&\ \ 1&\ \ 1\end{bmatrix}}}</annotation>
</semantics>
</math></span><img src="./91256bfeece3344f8602e288d445e6422c8b8a1c.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -4.005ex; width:17.467ex; height:9.176ex;" alt="{\displaystyle {\frac {1}{9}}{\begin{bmatrix}\ \ 1&\ \ 1&\ \ 1\\\ \ 1&\ \ 1&\ \ 1\\\ \ 1&\ \ 1&\ \ 1\end{bmatrix}}}" loading="lazy"></span>
</td>
<td><span class="mw-default-size" typeof="mw:File"></span>
</td></tr>
<tr>
<td><b><a href="Gaussian_blur" title="Gaussian blur">Gaussian blur</a> 3 × 3</b> <br> <small>(approximation)</small>
</td>
<td align="center"><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {1}{16}}{\begin{bmatrix}\ \ 1&\ \ 2&\ \ 1\\\ \ 2&\ \ 4&\ \ 2\\\ \ 1&\ \ 2&\ \ 1\end{bmatrix}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mn>1</mn>
<mn>16</mn>
</mfrac>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>2</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>2</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>4</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>2</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>2</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>1</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\frac {1}{16}}{\begin{bmatrix}\ \ 1&\ \ 2&\ \ 1\\\ \ 2&\ \ 4&\ \ 2\\\ \ 1&\ \ 2&\ \ 1\end{bmatrix}}}</annotation>
</semantics>
</math></span><img src="./ca9c0da52fe7818783942b06aac9cf396ae628bf.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -4.005ex; width:18.63ex; height:9.176ex;" alt="{\displaystyle {\frac {1}{16}}{\begin{bmatrix}\ \ 1&\ \ 2&\ \ 1\\\ \ 2&\ \ 4&\ \ 2\\\ \ 1&\ \ 2&\ \ 1\end{bmatrix}}}" loading="lazy"></span>
</td>
<td><span class="mw-default-size" typeof="mw:File"></span>
</td></tr>
<tr>
<td><b><a href="Gaussian_blur" title="Gaussian blur">Gaussian blur</a> 5 × 5</b> <br> <small>(approximation)</small>
</td>
<td align="center"><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {1}{256}}{\begin{bmatrix}1&4&6&4&1\\4&16&24&16&4\\6&24&36&24&6\\4&16&24&16&4\\1&4&6&4&1\end{bmatrix}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mn>1</mn>
<mn>256</mn>
</mfrac>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>6</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>16</mn>
</mtd>
<mtd>
<mn>24</mn>
</mtd>
<mtd>
<mn>16</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>6</mn>
</mtd>
<mtd>
<mn>24</mn>
</mtd>
<mtd>
<mn>36</mn>
</mtd>
<mtd>
<mn>24</mn>
</mtd>
<mtd>
<mn>6</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>16</mn>
</mtd>
<mtd>
<mn>24</mn>
</mtd>
<mtd>
<mn>16</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>6</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\frac {1}{256}}{\begin{bmatrix}1&4&6&4&1\\4&16&24&16&4\\6&24&36&24&6\\4&16&24&16&4\\1&4&6&4&1\end{bmatrix}}}</annotation>
</semantics>
</math></span><img src="./f91401a3e97428f14862afa1c781c55f4157580b.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -7.338ex; width:26.766ex; height:15.843ex;" alt="{\displaystyle {\frac {1}{256}}{\begin{bmatrix}1&4&6&4&1\\4&16&24&16&4\\6&24&36&24&6\\4&16&24&16&4\\1&4&6&4&1\end{bmatrix}}}" loading="lazy"></span>
</td>
<td><span class="mw-default-size" typeof="mw:File"></span>
</td></tr>
<tr>
<td><b><a href="Unsharp_masking" title="Unsharp masking">Unsharp masking</a> 5 × 5</b> <br>Based on Gaussian blur <br> with amount as 1 and <br> threshold as 0<br> <small>(with no <a href="Image_mask" class="mw-redirect" title="Image mask">image mask</a>)</small>
</td>
<td align="center"><span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\frac {-1}{256}}{\begin{bmatrix}1&4&\ \ 6&4&1\\4&16&\ \ 24&16&4\\6&24&-476&24&6\\4&16&\ \ 24&16&4\\1&4&\ \ 6&4&1\end{bmatrix}}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mfrac>
<mrow>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
<mn>256</mn>
</mfrac>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>6</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>16</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>24</mn>
</mtd>
<mtd>
<mn>16</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>6</mn>
</mtd>
<mtd>
<mn>24</mn>
</mtd>
<mtd>
<mo>−<!-- − --></mo>
<mn>476</mn>
</mtd>
<mtd>
<mn>24</mn>
</mtd>
<mtd>
<mn>6</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>16</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>24</mn>
</mtd>
<mtd>
<mn>16</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mtext> </mtext>
<mtext> </mtext>
<mn>6</mn>
</mtd>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>1</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\frac {-1}{256}}{\begin{bmatrix}1&4&\ \ 6&4&1\\4&16&\ \ 24&16&4\\6&24&-476&24&6\\4&16&\ \ 24&16&4\\1&4&\ \ 6&4&1\end{bmatrix}}}</annotation>
</semantics>
</math></span><img src="./259aa5d59203cb5fd7a04263ae9c09301c70dc97.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -7.338ex; width:29.736ex; height:15.843ex;" alt="{\displaystyle {\frac {-1}{256}}{\begin{bmatrix}1&4&\ \ 6&4&1\\4&16&\ \ 24&16&4\\6&24&-476&24&6\\4&16&\ \ 24&16&4\\1&4&\ \ 6&4&1\end{bmatrix}}}" loading="lazy"></span>
<p><br>
</p><p><br>
</p><p><br>
</p>
</td>
<td><span class="mw-default-size" typeof="mw:File"></span>
</td></tr>
</tbody></table>
<p>The above are just a few examples of effects achievable by convolving kernels and images.
</p>
<div class="mw-heading mw-heading3"><h3 id="Origin">Origin</h3></div>
<p>The origin is the position of the kernel which is above (conceptually) the current output pixel. This could be outside of the actual kernel, though usually it corresponds to one of the kernel elements. For a symmetric kernel, the origin is usually the center element.
</p>
<div class="mw-heading mw-heading2"><h2 id="Convolution">Convolution</h2></div>
<div role="note" class="hatnote navigation-not-searchable">See also: <a href="Symmetric_convolution" title="Symmetric convolution">Symmetric convolution</a></div>
<p>Convolution is the process of adding each element of the image to its local neighbors, weighted by the kernel. This is related to a form of <a href="Convolution" title="Convolution">mathematical convolution</a>. <a href="Hadamard_product_(matrices)" title="Hadamard product (matrices)">The matrix operation</a> being performed—convolution—is not traditional matrix multiplication, despite being similarly denoted by *.
</p><p>For example, if we have two three-by-three matrices, the first a kernel, and the second an image piece, convolution is the process of flipping both the rows and columns of the kernel and multiplying locally similar entries and summing. The element at coordinates [2, 2] (that is, the central element) of the resulting image would be a weighted combination of all the entries of the image matrix, with weights given by the kernel:
</p><p><span class="mwe-math-element mwe-math-element-block"><span class="mwe-math-mathml-display mwe-math-mathml-a11y" style="display: none;"><math display="block" xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle \left({\begin{bmatrix}a&b&c\\d&e&f\\g&h&i\end{bmatrix}}*{\begin{bmatrix}1&2&3\\4&5&6\\7&8&9\end{bmatrix}}\right)[2,2]=}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow>
<mo>(</mo>
<mrow>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mi>a</mi>
</mtd>
<mtd>
<mi>b</mi>
</mtd>
<mtd>
<mi>c</mi>
</mtd>
</mtr>
<mtr>
<mtd>
<mi>d</mi>
</mtd>
<mtd>
<mi>e</mi>
</mtd>
<mtd>
<mi>f</mi>
</mtd>
</mtr>
<mtr>
<mtd>
<mi>g</mi>
</mtd>
<mtd>
<mi>h</mi>
</mtd>
<mtd>
<mi>i</mi>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
<mo>∗<!-- ∗ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<mn>1</mn>
</mtd>
<mtd>
<mn>2</mn>
</mtd>
<mtd>
<mn>3</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>4</mn>
</mtd>
<mtd>
<mn>5</mn>
</mtd>
<mtd>
<mn>6</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mn>7</mn>
</mtd>
<mtd>
<mn>8</mn>
</mtd>
<mtd>
<mn>9</mn>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
</mrow>
<mo>)</mo>
</mrow>
<mo stretchy="false">[</mo>
<mn>2</mn>
<mo>,</mo>
<mn>2</mn>
<mo stretchy="false">]</mo>
<mo>=</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle \left({\begin{bmatrix}a&b&c\\d&e&f\\g&h&i\end{bmatrix}}*{\begin{bmatrix}1&2&3\\4&5&6\\7&8&9\end{bmatrix}}\right)[2,2]=}</annotation>
</semantics>
</math></span></span>
<span class="mwe-math-element mwe-math-element-block"><span class="mwe-math-mathml-display mwe-math-mathml-a11y" style="display: none;"><math display="block" xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle (i\cdot 1)+(h\cdot 2)+(g\cdot 3)+(f\cdot 4)+(e\cdot 5)+(d\cdot 6)+(c\cdot 7)+(b\cdot 8)+(a\cdot 9).}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mo stretchy="false">(</mo>
<mi>i</mi>
<mo>⋅<!-- ⋅ --></mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mo stretchy="false">(</mo>
<mi>h</mi>
<mo>⋅<!-- ⋅ --></mo>
<mn>2</mn>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mo stretchy="false">(</mo>
<mi>g</mi>
<mo>⋅<!-- ⋅ --></mo>
<mn>3</mn>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mo stretchy="false">(</mo>
<mi>f</mi>
<mo>⋅<!-- ⋅ --></mo>
<mn>4</mn>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mo stretchy="false">(</mo>
<mi>e</mi>
<mo>⋅<!-- ⋅ --></mo>
<mn>5</mn>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mo stretchy="false">(</mo>
<mi>d</mi>
<mo>⋅<!-- ⋅ --></mo>
<mn>6</mn>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mo stretchy="false">(</mo>
<mi>c</mi>
<mo>⋅<!-- ⋅ --></mo>
<mn>7</mn>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mo stretchy="false">(</mo>
<mi>b</mi>
<mo>⋅<!-- ⋅ --></mo>
<mn>8</mn>
<mo stretchy="false">)</mo>
<mo>+</mo>
<mo stretchy="false">(</mo>
<mi>a</mi>
<mo>⋅<!-- ⋅ --></mo>
<mn>9</mn>
<mo stretchy="false">)</mo>
<mo>.</mo>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle (i\cdot 1)+(h\cdot 2)+(g\cdot 3)+(f\cdot 4)+(e\cdot 5)+(d\cdot 6)+(c\cdot 7)+(b\cdot 8)+(a\cdot 9).}</annotation>
</semantics>
</math></span></span>
</p><p>The other entries would be similarly weighted, where we position the center of the kernel on each of the boundary points of the image, and compute a weighted sum.
</p><p>The values of a given pixel in the output image are calculated by multiplying each kernel value by the corresponding input image pixel values. This can be described algorithmically with the following pseudo-code:
</p>
<pre><b>for each</b> <i>image row</i> <b>in</b> <i>input image</i>:
<b>for each</b> <i>pixel</i> <b>in</b> <i>image row</i>:
<b>set</b> <i>accumulator</i> to zero
<b>for each</b> <i>kernel row</i> <b>in</b> <i>kernel</i>:
<b>for each</b> <i>element</i> <b>in</b> <i>kernel row</i>:
<b>if</b> <i>element position</i> corresponding* to <i>pixel position</i> <b>then</b>
<b>multiply</b> <i>element value</i> corresponding* to <i>pixel value</i>
<b>add</b> <i>result</i> to <i>accumulator</i>
<b>endif</b>
<b>set</b> <i>output image pixel</i> to <i>accumulator</i>
</pre>
<dl><dd>*corresponding input image pixels are found relative to the kernel's origin.</dd></dl>
<p>If the kernel is symmetric then place the center (origin) of the kernel on the current pixel. The kernel will overlap the neighboring pixels around the origin. Each kernel element should be multiplied with the pixel value it overlaps with and all of the obtained values should be summed. This resultant sum will be the new value for the current pixel currently overlapped with the center of the kernel.
</p><p>If the kernel is not symmetric, it has to be flipped both around its horizontal and vertical axis before calculating the convolution as above.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p><p>The general form for matrix convolution is
</p><p><span class="mwe-math-element mwe-math-element-block"><span class="mwe-math-mathml-display mwe-math-mathml-a11y" style="display: none;"><math display="block" xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle {\begin{bmatrix}x_{11}&x_{12}&\cdots &x_{1n}\\x_{21}&x_{22}&\cdots &x_{2n}\\\vdots &\vdots &\ddots &\vdots \\x_{m1}&x_{m2}&\cdots &x_{mn}\\\end{bmatrix}}*{\begin{bmatrix}y_{11}&y_{12}&\cdots &y_{1n}\\y_{21}&y_{22}&\cdots &y_{2n}\\\vdots &\vdots &\ddots &\vdots \\y_{m1}&y_{m2}&\cdots &y_{mn}\\\end{bmatrix}}=\sum _{i=0}^{m-1}\sum _{j=0}^{n-1}x_{(m-i)(n-j)}y_{(1+i)(1+j)}}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>11</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>12</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯<!-- ⋯ --></mo>
</mtd>
<mtd>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>21</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>22</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯<!-- ⋯ --></mo>
</mtd>
<mtd>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
<mtr>
<mtd>
<mo>⋮<!-- ⋮ --></mo>
</mtd>
<mtd>
<mo>⋮<!-- ⋮ --></mo>
</mtd>
<mtd>
<mo>⋱<!-- ⋱ --></mo>
</mtd>
<mtd>
<mo>⋮<!-- ⋮ --></mo>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>m</mi>
<mn>1</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>m</mi>
<mn>2</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯<!-- ⋯ --></mo>
</mtd>
<mtd>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>m</mi>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
<mo>∗<!-- ∗ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mrow>
<mo>[</mo>
<mtable rowspacing="4pt" columnspacing="1em">
<mtr>
<mtd>
<msub>
<mi>y</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>11</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>y</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>12</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯<!-- ⋯ --></mo>
</mtd>
<mtd>
<msub>
<mi>y</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>1</mn>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>y</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>21</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>y</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>22</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯<!-- ⋯ --></mo>
</mtd>
<mtd>
<msub>
<mi>y</mi>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
<mtr>
<mtd>
<mo>⋮<!-- ⋮ --></mo>
</mtd>
<mtd>
<mo>⋮<!-- ⋮ --></mo>
</mtd>
<mtd>
<mo>⋱<!-- ⋱ --></mo>
</mtd>
<mtd>
<mo>⋮<!-- ⋮ --></mo>
</mtd>
</mtr>
<mtr>
<mtd>
<msub>
<mi>y</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>m</mi>
<mn>1</mn>
</mrow>
</msub>
</mtd>
<mtd>
<msub>
<mi>y</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>m</mi>
<mn>2</mn>
</mrow>
</msub>
</mtd>
<mtd>
<mo>⋯<!-- ⋯ --></mo>
</mtd>
<mtd>
<msub>
<mi>y</mi>
<mrow class="MJX-TeXAtom-ORD">
<mi>m</mi>
<mi>n</mi>
</mrow>
</msub>
</mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</mrow>
<mo>=</mo>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>i</mi>
<mo>=</mo>
<mn>0</mn>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>m</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</munderover>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>j</mi>
<mo>=</mo>
<mn>0</mn>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mi>n</mi>
<mo>−<!-- − --></mo>
<mn>1</mn>
</mrow>
</munderover>
<msub>
<mi>x</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo stretchy="false">(</mo>
<mi>m</mi>
<mo>−<!-- − --></mo>
<mi>i</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">(</mo>
<mi>n</mi>
<mo>−<!-- − --></mo>
<mi>j</mi>
<mo stretchy="false">)</mo>
</mrow>
</msub>
<msub>
<mi>y</mi>
<mrow class="MJX-TeXAtom-ORD">
<mo stretchy="false">(</mo>
<mn>1</mn>
<mo>+</mo>
<mi>i</mi>
<mo stretchy="false">)</mo>
<mo stretchy="false">(</mo>
<mn>1</mn>
<mo>+</mo>
<mi>j</mi>
<mo stretchy="false">)</mo>
</mrow>
</msub>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle {\begin{bmatrix}x_{11}&x_{12}&\cdots &x_{1n}\\x_{21}&x_{22}&\cdots &x_{2n}\\\vdots &\vdots &\ddots &\vdots \\x_{m1}&x_{m2}&\cdots &x_{mn}\\\end{bmatrix}}*{\begin{bmatrix}y_{11}&y_{12}&\cdots &y_{1n}\\y_{21}&y_{22}&\cdots &y_{2n}\\\vdots &\vdots &\ddots &\vdots \\y_{m1}&y_{m2}&\cdots &y_{mn}\\\end{bmatrix}}=\sum _{i=0}^{m-1}\sum _{j=0}^{n-1}x_{(m-i)(n-j)}y_{(1+i)(1+j)}}</annotation>
</semantics>
</math></span></span>
</p>
<div class="mw-heading mw-heading3"><h3 id="Edge_handling">Edge handling</h3></div>
<p>Kernel convolution usually requires values from pixels outside of the image boundaries. There are a variety of methods for handling image edges.
</p>
<dl><dt>Extend</dt>
<dd>The nearest border pixels are conceptually extended as far as necessary to provide values for the convolution. Corner pixels are extended in 90° wedges. Other edge pixels are extended in lines.</dd>
<dt>Wrap</dt>
<dd>The image is conceptually wrapped (or tiled) and values are taken from the opposite edge or corner.</dd>
<dt>Mirror</dt>
<dd>The image is conceptually mirrored at the edges. For example, attempting to read a pixel 3 units outside an edge reads one 3 units inside the edge instead.</dd>
<dt>Crop / Avoid overlap</dt>
<dd>Any pixel in the output image which would require values from beyond the edge is skipped. This method can result in the output image being slightly smaller, with the edges having been cropped. Move kernel so that values from outside of image is never required. Machine learning mainly uses this approach. Example: Kernel size 10x10, image size 32x32, result image is 23x23.</dd>
<dt>Kernel Crop</dt>
<dd>Any pixel in the kernel that extends past the input image isn't used and the normalizing is adjusted to compensate.</dd>
<dt>Constant</dt>
<dd>Use constant value for pixels outside of image. Usually black or sometimes gray is used. Generally this depends on application.</dd></dl>
<div class="mw-heading mw-heading3"><h3 id="Normalization">Normalization</h3></div>
<p>Normalization is defined as the division of each element in the kernel by the sum of all kernel elements, so that the sum of the elements of a normalized kernel is unity. This will ensure the average pixel in the modified image is as bright as the average pixel in the original image.
</p>
<div class="mw-heading mw-heading3"><h3 id="Optimization">Optimization</h3></div>
<p>Fast convolution algorithms include:
</p>
<ul><li>separable convolution</li></ul>
<div class="mw-heading mw-heading4"><h4 id="Separable_convolution">Separable convolution</h4></div>
<p>2D convolution with an <i>M</i> × <i>N</i> kernel requires <i>M</i> × <i>N</i> multiplications for each sample (pixel). If the kernel is separable, then the computation can be reduced to <i>M</i> + <i>N</i> multiplications. Using separable convolutions can significantly decrease the computation by doing 1D convolution twice instead of one 2D convolution.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Implementation">Implementation</h3></div><p>
Here a concrete convolution implementation done with the <a href="OpenGL_Shading_Language" title="OpenGL Shading Language">GLSL</a> shading language :</p><div class="mw-highlight mw-highlight-lang-glsl mw-content-ltr" dir="ltr"><pre><span class="c1">// author : csblo</span>
<span class="c1">// Work made just by consulting :</span>
<span class="c1">// https://en.wikipedia.org/wiki/Kernel_(image_processing)</span>
<span class="c1">// Define kernels</span>
<span class="cp">#define identity mat3(0, 0, 0, 0, 1, 0, 0, 0, 0)</span>
<span class="cp">#define edge0 mat3(1, 0, -1, 0, 0, 0, -1, 0, 1)</span>
<span class="cp">#define edge1 mat3(0, 1, 0, 1, -4, 1, 0, 1, 0)</span>
<span class="cp">#define edge2 mat3(-1, -1, -1, -1, 8, -1, -1, -1, -1)</span>
<span class="cp">#define sharpen mat3(0, -1, 0, -1, 5, -1, 0, -1, 0)</span>
<span class="cp">#define box_blur mat3(1, 1, 1, 1, 1, 1, 1, 1, 1) * 0.1111</span>
<span class="cp">#define gaussian_blur mat3(1, 2, 1, 2, 4, 2, 1, 2, 1) * 0.0625</span>
<span class="cp">#define emboss mat3(-2, -1, 0, -1, 1, 1, 0, 1, 2)</span>
<span class="c1">// Find coordinate of matrix element from index</span>
<span class="kt">vec2</span><span class="w"> </span><span class="n">kpos</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">index</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="kt">vec2</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span><span class="w"> </span><span class="p">(</span>
<span class="w"> </span><span class="kt">vec2</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">),</span><span class="w"> </span><span class="kt">vec2</span><span class="p">(</span><span class="mo">0</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">),</span><span class="w"> </span><span class="kt">vec2</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="o">-</span><span class="mi">1</span><span class="p">),</span>
<span class="w"> </span><span class="kt">vec2</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mo">0</span><span class="p">),</span><span class="w"> </span><span class="kt">vec2</span><span class="p">(</span><span class="mo">0</span><span class="p">,</span><span class="w"> </span><span class="mo">0</span><span class="p">),</span><span class="w"> </span><span class="kt">vec2</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mo">0</span><span class="p">),</span><span class="w"> </span>
<span class="w"> </span><span class="kt">vec2</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">),</span><span class="w"> </span><span class="kt">vec2</span><span class="p">(</span><span class="mo">0</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">),</span><span class="w"> </span><span class="kt">vec2</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span>
<span class="w"> </span><span class="p">)[</span><span class="n">index</span><span class="p">]</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">iResolution</span><span class="p">.</span><span class="n">xy</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// Extract region of dimension 3x3 from sampler centered in uv</span>
<span class="c1">// sampler : texture sampler</span>
<span class="c1">// uv : current coordinates on sampler</span>
<span class="c1">// return : an array of mat3, each index corresponding with a color channel</span>
<span class="kt">mat3</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="w"> </span><span class="n">region3x3</span><span class="p">(</span><span class="kt">sampler2D</span><span class="w"> </span><span class="n">sampler</span><span class="p">,</span><span class="w"> </span><span class="kt">vec2</span><span class="w"> </span><span class="n">uv</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="c1">// Create each pixels for region</span>
<span class="w"> </span><span class="kt">vec4</span><span class="p">[</span><span class="mi">9</span><span class="p">]</span><span class="w"> </span><span class="n">region</span><span class="p">;</span>
<span class="w"> </span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mo">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">9</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">texture</span><span class="p">(</span><span class="n">sampler</span><span class="p">,</span><span class="w"> </span><span class="n">uv</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">kpos</span><span class="p">(</span><span class="n">i</span><span class="p">));</span>
<span class="w"> </span><span class="c1">// Create 3x3 region with 3 color channels (red, green, blue)</span>
<span class="w"> </span><span class="kt">mat3</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="w"> </span><span class="n">mRegion</span><span class="p">;</span>
<span class="w"> </span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mo">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">3</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="w"> </span><span class="n">mRegion</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">mat3</span><span class="p">(</span>
<span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="mo">0</span><span class="p">][</span><span class="n">i</span><span class="p">],</span><span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="n">i</span><span class="p">],</span><span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
<span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="mi">3</span><span class="p">][</span><span class="n">i</span><span class="p">],</span><span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="mi">4</span><span class="p">][</span><span class="n">i</span><span class="p">],</span><span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="mi">5</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
<span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="mi">6</span><span class="p">][</span><span class="n">i</span><span class="p">],</span><span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="mi">7</span><span class="p">][</span><span class="n">i</span><span class="p">],</span><span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="mi">8</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
<span class="w"> </span><span class="p">);</span>
<span class="w"> </span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">mRegion</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// Convolve a texture with kernel</span>
<span class="c1">// kernel : kernel used for convolution</span>
<span class="c1">// sampler : texture sampler</span>
<span class="c1">// uv : current coordinates on sampler</span>
<span class="kt">vec3</span><span class="w"> </span><span class="n">convolution</span><span class="p">(</span><span class="kt">mat3</span><span class="w"> </span><span class="n">kernel</span><span class="p">,</span><span class="w"> </span><span class="kt">sampler2D</span><span class="w"> </span><span class="n">sampler</span><span class="p">,</span><span class="w"> </span><span class="kt">vec2</span><span class="w"> </span><span class="n">uv</span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="kt">vec3</span><span class="w"> </span><span class="n">fragment</span><span class="p">;</span>
<span class="w"> </span>
<span class="w"> </span><span class="c1">// Extract a 3x3 region centered in uv</span>
<span class="w"> </span><span class="kt">mat3</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="w"> </span><span class="n">region</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">region3x3</span><span class="p">(</span><span class="n">sampler</span><span class="p">,</span><span class="w"> </span><span class="n">uv</span><span class="p">);</span>
<span class="w"> </span>
<span class="w"> </span><span class="c1">// for each color channel of region</span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mo">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">3</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="c1">// get region channel</span>
<span class="w"> </span><span class="kt">mat3</span><span class="w"> </span><span class="n">rc</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">region</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
<span class="w"> </span><span class="c1">// component wise multiplication of kernel by region channel</span>
<span class="w"> </span><span class="kt">mat3</span><span class="w"> </span><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">matrixCompMult</span><span class="p">(</span><span class="n">kernel</span><span class="p">,</span><span class="w"> </span><span class="n">rc</span><span class="p">);</span>
<span class="w"> </span><span class="c1">// add each component of matrix</span>
<span class="w"> </span><span class="kt">float</span><span class="w"> </span><span class="n">r</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">c</span><span class="p">[</span><span class="mo">0</span><span class="p">][</span><span class="mo">0</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">c</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mo">0</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">c</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mo">0</span><span class="p">]</span>
<span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">c</span><span class="p">[</span><span class="mo">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">c</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">c</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">1</span><span class="p">]</span>
<span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">c</span><span class="p">[</span><span class="mo">0</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">c</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">c</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">2</span><span class="p">];</span>
<span class="w"> </span>
<span class="w"> </span><span class="c1">// for fragment at channel i, set result</span>
<span class="w"> </span><span class="n">fragment</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">r</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">fragment</span><span class="p">;</span><span class="w"> </span>
<span class="p">}</span>
<span class="kt">void</span><span class="w"> </span><span class="n">mainImage</span><span class="p">(</span><span class="w"> </span><span class="k">out</span><span class="w"> </span><span class="kt">vec4</span><span class="w"> </span><span class="n">fragColor</span><span class="p">,</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="kt">vec2</span><span class="w"> </span><span class="n">fragCoord</span><span class="w"> </span><span class="p">)</span>
<span class="p">{</span>
<span class="w"> </span><span class="c1">// Normalized pixel coordinates (from 0 to 1)</span>
<span class="w"> </span><span class="kt">vec2</span><span class="w"> </span><span class="n">uv</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">fragCoord</span><span class="o">/</span><span class="n">iResolution</span><span class="p">.</span><span class="n">xy</span><span class="p">;</span>
<span class="w"> </span><span class="c1">// Convolve kernel with texture</span>
<span class="w"> </span><span class="kt">vec3</span><span class="w"> </span><span class="n">col</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">convolution</span><span class="p">(</span><span class="n">emboss</span><span class="p">,</span><span class="w"> </span><span class="n">iChannel0</span><span class="p">,</span><span class="w"> </span><span class="n">uv</span><span class="p">);</span>
<span class="w"> </span>
<span class="w"> </span><span class="c1">// Output to screen</span>
<span class="w"> </span><span class="n">fragColor</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">vec4</span><span class="p">(</span><span class="n">col</span><span class="p">,</span><span class="w"> </span><span class="mf">1.0</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Convolution" title="Convolution">Convolution in mathematics </a></li>
<li><a href="Multidimensional_discrete_convolution" title="Multidimensional discrete convolution">Multidimensional discrete convolution</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://www.songho.ca/dsp/convolution/convolution2d_example.html">"Example of 2D Convolution"</a>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.songho.ca/dsp/convolution/convolution.html">"Convolution"</a>. <i>www.songho.ca</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2022-11-19</span></span>.</cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="Sources">Sources</h2></div>
<ul><li><cite id="CITEREFLudwig" class="citation book cs1">Ludwig, Jamie (n.d.). <a rel="nofollow" class="external text" href="http://web.pdx.edu/~jduh/courses/Archive/geog481w07/Students/Ludwig_ImageConvolution.pdf"><i>Image Convolution</i></a> <span class="cs1-format">(PDF)</span>. Portland State University.</cite></li>
<li><cite id="CITEREFLecarmeDelvare2013" class="citation book cs1">Lecarme, Olivier; Delvare, Karine (January 2013). <i>The Book of GIMP: A Complete Guide to Nearly Everything</i>. No Starch Press. p. 429. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-1593273835</bdi>.</cite></li>
<li><cite id="CITEREFGumsterShimonski2012" class="citation book cs1">Gumster, Jason van; Shimonski, Robert (March 2012). <i>GIMP Bible</i>. John Wiley & Sons. pp. <span class="nowrap">438–</span>442. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-0470523971</bdi>.</cite></li>
<li><cite id="CITEREFShapiroStockman2001" class="citation book cs1"><a href="Linda_Shapiro" title="Linda Shapiro">Shapiro, Linda G.</a>; Stockman, George C. (February 2001). <i>Computer Vision</i>. Prentice Hall. pp. <span class="nowrap">53–</span>54. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-0130307965</bdi>.</cite></li></ul>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><a rel="nofollow" class="external text" href="https://www.youtube.com/watch?v=38lj0VQci7E">Implementing 2d convolution on FPGA</a></li>
<li><a rel="nofollow" class="external text" href="https://developer.apple.com/library/content/documentation/Performance/Conceptual/vImage/ConvolutionOperations/ConvolutionOperations.html">vImage Programming Guide: Performing Convolution Operations</a></li>
<li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20121005005358/http://williamson-labs.com/convolution-2d.htm">Image Processing using 2D-Convolution</a></li>
<li><a rel="nofollow" class="external text" href="https://docs.gimp.org/2.8/en/plug-in-convmatrix.html">GNU Image Manipulation Program - User Manual - 8.2. Convolution Matrix</a></li>
<li><a rel="nofollow" class="external text" href="https://www.shadertoy.com/view/3sGXWh">GLSL Demonstration of 3x3 Convolution Kernels</a></li>
<li><a rel="nofollow" class="external text" href="https://github.com/Geof23/kernel_filter_2d">Complete C++ open source project</a></li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-05-20" href="https://en.wikipedia.org/wiki/?title=Kernel_(image_processing)&oldid=1291268789">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>